home *** CD-ROM | disk | FTP | other *** search
-
- /* txthgt.c --- textheight, BIBLE p. 861 */
-
- #include <graphics.h>
- #define ESC '\033' /* The ASCII code for Escape */
- main()
- {
- int graphdriver = DETECT, graphmode, xmax, ymax,
- xsize, ysize, c, x, y;
- char outstr[2] = " ";
- /* Detect and initialize graphics system */
- initgraph(&graphdriver, &graphmode, "c:\\turboc");
- /* Define a viewport */
- xmax = getmaxx();
- ymax = getmaxy();
- xsize = xmax - 100;
- ysize = ymax - 60;
- outtextxy(10, 10, "Press Esc followed by any other key to exit");
- setviewport(50, 30, xsize+50, ysize+30, 1);
- setfillstyle(SOLID_FILL, RED);
- bar3d(0, 0, xsize, ysize, 0, 1);
- setcolor(YELLOW);
- settextjustify(LEFT_TEXT, BOTTOM_TEXT);
- /* Read characters and print them to the viewport.
- * When the edge of the viewport is reached, move
- * down by the height of the character plus 4 pixels.
- * Exit the loop when user presses the Escape key. */
- settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
- x = 4;
- y = textheight("H") + 4;
- moveto(x, y);
- while ((c = getch()) != ESC)
- {
- outstr[0] = c;
- if ((c == '\r') || (x + textwidth(outstr)) > xsize)
- /* Advance to the next line in the viewport */
- {
- x = 4;
- y += textheight("H");
- moveto(x, y);
- }
- /* Print text. Don't print carriage return */
- if (c != '/r')
- outtext(outstr);
- x += textwidth(outstr);
- }
- /* Wait for final key press before exiting */
- getch();
- /* Close graphics system when done */
- closegraph();
- }